SetErrorHandler

Syntax: @SetErrorHandler function

SetErrorHandler is an exception handling command.

function is the name of a function to be executed when a run time exception arises. This user defined function takes three string parameters and returns a numeric code.

The three string parameters represent:

·Where the error occurred (which object).

·What the error is (the error message).

·Procedure only: the procedure text of the line in which the error has occurred.

The return value should be set to indicate what the next step should be:

·0 means if possible, continue running despite the error.

·1 means halt the runtime if possible (e.g. this would not be possible if the error was inside event handling procedures).

·2 means skip the rest of the procedure in which the error occurs.

Example

@SetErrorHandler Error_Proc

When this command is executed (i.e. encountered at run time) it will attempt to call the Procedure Error_Proc, which could contain this function:

Function (s1:S,  s2:S,  s3:S) : N
@Dim s:S
@Assign s = 'ERROR:- ' + s2 + ' occurred  in (' + s1 + ')'
@If s3 <> ''
    @Assign s = s + ', line: (' + s3+ ')'
@Endif
@Debug s @Rem or you can write (s) to a text file instead
@Return 1 @Rem halt the application (if possible)

This command will attempt to handle all errors but note that this will not always be possible. For example, fatal run time errors cannot be avoided.